# Maintainer: Peter Budai <peterbudai@hotmail.com>

_realname=ptyprocess
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}" "${MINGW_PACKAGE_PREFIX}-python2-${_realname}")
pkgver=0.5.2
pkgrel=1
pkgdesc="Run a subprocess in a pseudo terminal (mingw-w64)"
url="https://github.com/pexpect/ptyprocess"
arch=('any')
license=('ISC')
makedepends=("${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools")
source=(${_realname}-${pkgver}.tar.gz::https://pypi.io/packages/source/p/${_realname}/${_realname}-${pkgver}.tar.gz
            'https://raw.githubusercontent.com/pexpect/ptyprocess/master/LICENSE')
sha256sums=('e64193f0047ad603b71f202332ab5527c5e52aa7c8b609704fc28c0dc20c4365'
            'c822d385b1a73329846241799becf18690b5d44764c1bed69300b536a405030a')


prepare() {
  cd "$srcdir"/

  for pver in {2,3}; do
    rm -rf python${pver}-build-${CARCH} | true
    cp -r "${_realname}-${pkgver}" "python${pver}-build-${CARCH}"
  done

}

build() {
  for pver in {2,3}; do
    msg "Python ${pver} build for ${CARCH}"
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done
}

package_python3-ptyprocess() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3")

  cd ${srcdir}/"python${pver}-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --root=${pkgdir} --prefix=${MINGW_PREFIX} --optimize=1

  install -D -m644 "$srcdir/LICENSE" ${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE
}

package_python2-ptyprocess() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2")

  cd ${srcdir}/"python${pver}-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --root=${pkgdir} --prefix=${MINGW_PREFIX} --optimize=1

  install -D -m644 "$srcdir/LICENSE" ${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE
}

package_mingw-w64-i686-python2-ptyprocess() {
  package_python2-ptyprocess
}

package_mingw-w64-i686-python3-ptyprocess() {
  package_python3-ptyprocess
}

package_mingw-w64-x86_64-python2-ptyprocess() {
  package_python2-ptyprocess
}

package_mingw-w64-x86_64-python3-ptyprocess() {
  package_python3-ptyprocess
}
